/// beamnpc.txt
// A monster with a special ability scripted in. The ability is an beam, used 
// 50% of the time.

// Memory Cells:
//   Cell 0 - If 0, default behavior. If 1, it doesnt fidget.
//   Cell 1,2 - Stuff done flag. If both 0, nothing. Otherwise when this is killed, set to 1.
//   Cell 4 - The ability to use.
//   Cell 5 - talking

// The abilities:
// 0 - Beam Slow
// 1 - Beam Curse
// 2 - Beam Fire (1-6 dam per level)
// 3 - Beam Acid
// 4 - Beam Terror
// 5 - Beam Daze
// 6 - Beam Debuff
// 7 - Beam Cold (1-8 dam per level)
// 8 - Beam Energy (1-10 dam per level)
// 9 - Beam Charm
// 10 - unused
// 11 - Beam lightning

begincreaturescript;

variables;

short i,target;
short last_abil;
short used_abil = 0;
short mental_effect = 0;

body;

beginstate INIT_STATE;
	set_name(ME,"Balme");
	set_boss_level(ME,2);
	
	
	last_abil = get_current_tick();

	if (gf(43,1) > 0)
		erase_char(ME);
	break;

beginstate DEAD_STATE;
	sf(43,1,1);
break;

beginstate START_STATE; 
	if ((get_nearest_party_char(5) >= 0) && (get_attitude(ME) < 10)) {
		talk_no_exit(30);
		}
		
	// if I have a target for some reason, go attack it
	if (target_ok()) {
		//if (dist_to_char(get_target()) <= 16)
			set_state(3);
		//	else set_foe_target(ME,-1);
		}
	
	if (get_foe_target(ME,8,0)) {
		do_attack();
		set_state(3);
		}
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}


	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking
	if (target_ok() == FALSE)
		set_state(START_STATE);
	used_abil = 0;

	if ((can_see_char(get_target())) && (is_combat()) && (tick_difference(last_abil,get_current_tick()) > 0)) {
		run_char_animation(2,1,35);	

			print_named_str(ME,"blasts you with a wand.");
			if (get_target() == pc_num())
				set_char_status(get_target(),20,3);
				else set_char_status(get_target(),7,30);

			set_char_status(get_target(),9,-15);
			set_char_status(get_target(),11,-15);
			set_char_status(get_target(),12,-15);
			set_char_status(get_target(),13,-15);
			set_char_status(get_target(),14,-15);
			set_char_status(get_target(),15,-15);
			set_char_status(get_target(),16,-15);
			set_char_status(get_target(),18,-15);
			set_char_status(get_target(),19,-15);
			place_particle_num(get_target(),8,2,8);
			pc_heard_sound_delay(195,100);						
			used_abil = 1;


		last_abil = get_current_tick();
		end();
		}

	if (used_abil == 0)
		do_attack();
break;

beginstate TALKING_STATE;
	begin_talk_mode(30);
break;